﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="news_submit_edit.aspx.cs" validateRequest=false  Inherits="Ccit.OA.NewsCenter.news_submit_edit" %>

<%@ Register Assembly="FreeTextBox" Namespace="FreeTextBoxControls" TagPrefix="FTB" %>

<%@ Register TagPrefix="ccit" TagName="attach" Src="../UserControls/AttachUpLoad.ascx" %>

<%@ Register TagPrefix="ccit" Namespace="Ccit.ServerControls" Assembly="Ccit.ServerControls.ActionForm" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript" src="../script/jwindow.js"></script>
    <script language="javascript" type="text/javascript" src="../script/jsonlib.js"></script>
    <script language="javascript" type="text/javascript" src="../script/jQuery.js"></script>
    <script language="javascript" type="text/javascript" src="../script/jbase64.js"></script>
    <script type="text/javascript" language="javascript" for=WebOffice event="OnMenuClick(vIndex,vCaption)">

       if (vIndex==1){  //打开本地文件
          WebOpenLocal();
       }
       if (vIndex==2){  //保存本地文件
          WebSaveLocal();
       }
       if (vIndex==3){  //保存到服务器上
          SaveDocument();    //保存正文
       }
       if (vIndex==5){  //签名印章
          WebOpenSignature();
       }
       if (vIndex==6){  //验证签章
          WebShowSignature();
       }
       if (vIndex==8){  //保存版本
          WebSaveVersion();
       }
       if (vIndex==9){  //打开版本
          WebOpenVersion();
       }
       if (vIndex==14){  //保存并退出
         SaveDocument();    //保存正文
         webform.submit();
       }
       if (vIndex==16){  //打印文档
          WebOpenPrint();
       }
       if (vIndex==17){  //隐藏手写批注
          webform.WebOffice.VisibleTools('手写批注',false);   //隐藏或显示iWebOffice工具栏 true显示  false隐藏
       }
       if (vIndex==18){  //显示手写批注
          webform.WebOffice.VisibleTools('手写批注',false);   //隐藏或显示iWebOffice工具栏 true显示  false隐藏
       }

    </script>
    <script language="javascript" type="text/javascript">
    <!--
        /* Select Image for News */
        function doSelectImage()
        {
            var oNewsId=document.getElementById("hdId").value;
            if(oNewsId=="")
            {
                alert("请先保存当前信息再上传图片！");
            }
            else
            {
                var oType=document.getElementById("hdType").value;
                var vPageParam="at=1&Type="+oType+"&Id="+oNewsId;
                //var encodeParam=base64encode(vPageParam);
                OpenWindow("news_submit_addpic.aspx?"+vPageParam,"",440,400,false);
            }
        }
        
        /* Show/Hidden Select Image */
        function doShowSelImage()
        {
            var oChkSelImage=document.getElementById("chkHasImage");
            if(oChkSelImage.checked)
                document.getElementById("haSelImage").style.visibility="visible";
            else
                document.getElementById("haSelImage").style.visibility="hidden";
        }
        
        function doSelContentType()
        {
            var oType=GetCheckedContentType();
            if(oType=="0")//HTML
            {
                document.getElementById("trHtmlContent").style.display="block";
                document.getElementById("trUrl").style.display="none";
                document.getElementById("EDITOR_WORD").style.display="none";
            }
            else if(oType=="1")//WORD
            {
                document.getElementById("EDITOR_WORD").style.display="block";
                document.getElementById("trHtmlContent").style.display="none";
                document.getElementById("trUrl").style.display="none";
                InitOffice(".doc");
            }
            else if(oType=="2")//EXCEL
            {
                document.getElementById("EDITOR_WORD").style.display="block";
                document.getElementById("trHtmlContent").style.display="none";
                document.getElementById("trUrl").style.display="none";
                InitOffice(".xls");
            }
            else if(oType=="3")//链接地址
            {
                document.getElementById("trHtmlContent").style.display="none";
                document.getElementById("trUrl").style.display="block";
                document.getElementById("EDITOR_WORD").style.display="none";
            }
        }
        
        /* Back To List Page */
        function doBack()
        {
            var oType=document.getElementById("hdType").value;
            var oFrom = document.getElementById("hdFrom").value;
            var vPageParam="Type="+oType;
            var encodeParam=base64encode(vPageParam);
            if(oFrom=="0")
                window.location.href="news_submit_list.aspx?"+encodeParam;
            else if(oFrom == "1")
                window.location.href="news_list_manage.aspx?"+encodeParam;
        }
        
        /* UpLoad File */
        function doUploadFile()
        {
            OpenUpLoadPage();
        }
        
        /* Save News Info */
        function doSave(oSaveType)
        {
            document.getElementById("hdSaveType").value=oSaveType;
            var oContentType=GetCheckedContentType();
            if(oContentType=="0") //HTML
            {
                __doPostBack("lnkSave","");
            }
            else if(oContentType=="1") //WORD
            {
                webform.WebOffice.WebSetMsgByName("NEWS",GetNewsObject());
                SaveDocument();
                ClientCallBack();             
            }
            else if(oContentType=="2")//EXCEL
            {
                webform.WebOffice.WebSetMsgByName("NEWS",GetNewsObject());
                SaveDocument();
                ClientCallBack();
            }
            else if(oContentType=="3")//URL
            {
                __doPostBack("lnkSave","");
            }
        }
        
        function ClientCallBack()
        {
            var oNewsId = webform.WebOffice.WebGetMsgByName("ID");
            var oSaveType=document.getElementById("hdSaveType").value;
            if(oNewsId!="")
            {
                alert("保存成功！");
                if(oSaveType=="1")  /* Save */
                {
                    document.getElementById("hdId").value=oNewsId;
                    document.getElementById("hdContentType").value=webform.WebOffice.WebGetMsgByName("NEWCONTENTTYPE");
                }
                else if(oSaveType=="2") /* Save Continue */
                {
                    document.getElementById("hdContentType").value=webform.WebOffice.WebGetMsgByName("NEWCONTENTTYPE");
                    DisponsePage();
                    __doPostBack("lnkRefresh","");
                }
                else if(oSaveType=="3") /* SaveBack */
                {
                    doBack();
                }
            }
            else
            {
                alert("保存失败，请稍后再试！");
            }
        }
        
        function DisponsePage()
        {
            document.getElementById("txtNewsTitle").value="";
            document.getElementById("radHtml").checked=true;
            document.getElementById("ddlColumn").value="";
            document.getElementById("chkTop").checked=false;
            document.getElementById("chkAllowDiscuss").checked=false;
            document.getElementById("chkHasImage").checked=false;
            document.getElementById("hdId").value="";
            document.getElementById("ftbContent").value="";
            document.getElementById("txtUrl").value="";
            document.getElementById("haSelImage").style.visibility="hidden";
            document.getElementById("trHtmlContent").style.display="block";
            document.getElementById("trUrl").style.display="none";
            document.getElementById("EDITOR_WORD").style.display="none";
            ClearShowAttaches();
        }
        
        /* Get News Object */
        function GetNewsObject()
        {
            var oNewsId=document.getElementById("hdId").value;
            var oTypeId=document.getElementById("hdType").value;
            var oContentType = GetCheckedContentType();
            var oNewsTitle = jQuery.trim(document.getElementById("txtNewsTitle").value);
            var oColumn = jQuery.trim(document.getElementById("ddlColumn").value);
            var oTopFlag = (document.getElementById("chkTop").checked) ? "1" : "0";
            var oAllowDiscuss = (document.getElementById("chkAllowDiscuss").checked) ? "1" : "0";
            var oHasImage = (document.getElementById("chkHasImage").checked) ? "1" : "0";
            var oNewsStatus=document.getElementById("hdNewsStatus").value;
            var oNewsObj={};
            oNewsObj.NewsId = oNewsId;
            oNewsObj.ColumnNo = oColumn;
            oNewsObj.NewsTitle = oNewsTitle;
            oNewsObj.TopFlag = oTopFlag;
            oNewsObj.PicFlag = oHasImage;
            oNewsObj.CommentFlag = oAllowDiscuss;
            oNewsObj.ContentFormat = oContentType;
            oNewsObj.NewsStatus = (oNewsStatus!="")?oNewsStatus:"0";

            oNewsObj.NewsType = oTypeId;
            oNewsObj.ConnectAddress = "";
            oNewsObj.NewsContent = "";
            var oNewsInfo = JSON.stringify(oNewsObj,function(key,value){return value;});
            return oNewsInfo;
        }
        
        /* Get Checked Content Type */
        function GetCheckedContentType()
        {
            var oCheckedContentType="";
            var oContentType=document.getElementsByName("radContentType");
            var oContentTypeCount=oContentType.length;
            for(var i=0;i<oContentTypeCount;i++)
            {
                if(oContentType.item(i).checked)
                {
                    oCheckedContentType=i;
                    break;
                }
            }
            return oCheckedContentType;
        }
        
        /* Init Page Info */
        function doLoad()
        {
            doSelContentType();
            var oId=document.getElementById("hdId").value;
            var oOldContentType=document.getElementById("hdContentType").value;
            var oType=GetCheckedContentType();
            if(oType=="1"||oType=="2")
            {
                try
                {
                    webform.WebOffice.WebUrl=document.getElementById("hdWebUrl").value;			//WebUrl:系统服务器路径，与服务器文件交互操作，如保存、打开文档，重要文件                    if(oType==oOldContentType)
                    {
                        webform.WebOffice.WebSetMsgByName("NEWSID",oId);   //记录ID
                    }
                    else
                    {
                        webform.WebOffice.WebSetMsgByName("NEWSID","");   //记录ID
                    }
                    
                    
                    
                    webform.WebOffice.RecordID=document.getElementById("hdRecordID").value;		//RecordID:本文档记录编号
                    webform.WebOffice.Template=document.getElementById("hdTemplate").value;		//Template:模板编号
                    webform.WebOffice.FileName=document.getElementById("hdFileName").value;		//FileName:文档名称
                    webform.WebOffice.FileType=document.getElementById("hdFileType").value;		//FileType:文档类型  .doc  .xls  .wps
                    webform.WebOffice.UserName=document.getElementById("hdUserName").value;		//UserName:操作用户名，痕迹保留需要
                    webform.WebOffice.EditType=document.getElementById("hdEditType").value;		//EditType:编辑类型  方式一、方式二  <参考技术文档>  
														                //第一位可以为0,1,2,3 其中:0不可编辑;1可以编辑,无痕迹;2可以编辑,有痕迹,不能修订;3可以编辑,有痕迹,能修订；
														                //第二位可以为0,1 其中:0不可批注,1可以批注。可以参考iWebOffice2006的EditType属性，详细参考技术白皮书
                    webform.WebOffice.MaxFileSize = 16 * 1024;			//最大的文档大小控制，默认是64M，现在设置成16M。        
                    //Start  iWebOffice2006属性  以下属性可以不要
                    webform.WebOffice.Language="CH";					//Language:多语言支持显示选择   CH 简体 TW繁体 EN英文
                    webform.WebOffice.PenColor="#FF0000";				//PenColor:默认批注颜色
                    webform.WebOffice.PenWidth="1";						//PenWidth:默认批注笔宽
                    webform.WebOffice.Print="1";						//Print:默认是否可以打印:1可以打印批注,0不可以打印批注
                    webform.WebOffice.ShowToolBar="1";					//ShowToolBar:是否显示工具栏:1显示,0不显示

                    webform.WebOffice.ShowMenu="1";
                    webform.WebOffice.AppendMenu("1","打开本地文件(&L)");
                    webform.WebOffice.AppendMenu("2","保存本地文件(&S)");
                    webform.WebOffice.AppendMenu("3","保存远程文件(&U)");
//                    webform.WebOffice.AppendMenu("4","-");
//                    webform.WebOffice.AppendMenu("5","签名印章(&Q)");
//                    webform.WebOffice.AppendMenu("6","验证签章(&Y)");
                    webform.WebOffice.AppendMenu("7","-");
                    webform.WebOffice.AppendMenu("8","保存版本(&B)");
                    webform.WebOffice.AppendMenu("9","打开版本(&D)");
                    webform.WebOffice.AppendMenu("13","-");
                    webform.WebOffice.AppendMenu("14","保存并退出(&E)");
                    webform.WebOffice.AppendMenu("15","-");
                    webform.WebOffice.AppendMenu("16","打印文档(&P)");
                    webform.WebOffice.AppendMenu("主菜单","-");
                    webform.WebOffice.AppendMenu("17","隐藏手写批注(&C)");
                    webform.WebOffice.AppendMenu("18","显示手写批注(&O)");
                    webform.WebOffice.DisableMenu("宏(&M);选项(&O)...");	//禁止菜单
                    //End

                    webform.WebOffice.WebOpen();
                    webform.WebOffice.ShowType=1;				//文档显示方式  1:表示文字批注  2:表示手写批注  0:表示文档核稿

                }catch(e){
                    alert(e.description);									//显示出错误信息
                }
            }
        }
        
        /* 初始化Office控件 */
        function InitOffice(oFileType)
        {         
            document.getElementById("hdRecordID").value="";
            document.getElementById("hdTemplate").value="";
            document.getElementById("hdFileName").value="";
            document.getElementById("hdFileType").value=oFileType;
            document.getElementById("hdUserName").value="";
            document.getElementById("hdEditType").value="1,1";            
        }
        
        //作用：退出iWebOffice
        function UnLoad()
        {
            var oContentType=GetCheckedContentType();
            if(oContentType=="1"||oContentType=="2")
            {
                try{
                    webform.WebOffice.WebClose()
                }catch(e){alert(e.description);}
            }
        }
        
        
        //作用：打开文档
        function LoadDocument()
        {
            try
            {
                webform.WebOffice.WebOpen();
            }catch(e)
            {
                alert(e.description);
            }   
        }
        
        //作用：保存文档
        function SaveDocument()
        {
            try
            {
                webform.WebOffice.WebSetMsgByName("Attaches",GetAttachesXML("2"));
                webform.WebOffice.WebSave();//交互OfficeServer的OPTION="SAVEFILE"  注：WebSave()是保存复合格式文件，包括OFFICE内容和手写批注文档；如只保存成OFFICE文档格式，那么就设WebSave(true)
            }catch(e)
            {
                alert(e.description);
            }   
        }
    //-->
    </script>
    
</head>
<body onload="doLoad()" onunload="UnLoad()">
    <ccit:ActionForm id="webform" name="webform" runat="server">
        <input type="hidden" id="hdId" runat="server" />
        <input type="hidden" id="hdType" runat="server" />
        <input type="hidden" id="_hidSource" runat="server" />
        <input type="hidden" id="hdContentType" runat="server" />
        <%-- 来源 0：发布列表；1：管理列表 --%>
        <input type="hidden" id="hdFrom" runat="server" />
        <%-- 信息状态 --%>
        <input type="hidden" id="hdNewsStatus" runat="server" />
        <asp:LinkButton ID="lnkSave" style="display:none" runat="server" onclick="lnkSave_Click"></asp:LinkButton>
        <asp:LinkButton ID="lnkRefresh" style="display:none" runat="server" onclick="lnkRefresh_Click"></asp:LinkButton>
        <input type="hidden" id="hdSaveType" runat="server" />
        
        <%-- 金格控件必备属性 --%>
        
        <%-- 系统服务器路径，与服务器文件交互操作，如保存、打开文档，重要文件 --%>
        <input type="hidden" id="hdWebUrl" runat="server" />
        <%-- 本文档记录编号 --%>
        <input type="hidden" id="hdRecordID" runat="server" />
        <%-- 模板编号 --%>
        <input type="hidden" id="hdTemplate" runat="server" />
        <%-- 文档名称 --%>
        <input type="hidden" id="hdFileName" runat="server" />
        <%-- 文档类型  .doc  .xls  .wps --%>
        <input type="hidden" id="hdFileType" runat="server" />
        <%-- 操作用户名，痕迹保留需要 --%>
        <input type="hidden" id="hdUserName" runat="server" />
        <%-- 
            编辑类型 
            第一位可以为0,1,2,3 其中:0不可编辑;1可以编辑,无痕迹;2可以编辑,有痕迹,不能修订;3可以编辑,有痕迹,能修订；
            第二位可以为0,1 其中:0不可批注,1可以批注。
        --%>
        <input type="hidden" id="hdEditType" runat="server" />
        
        
        <%-- 金格控件必备属性 --%>
        
        <table class="tbToolbar" cellpadding="0" cellspacing="0" align="center" width="98%">
            <tr>
                <td align="left">
                    <div class="tbSeparator"></div>                    
                </td>
                <td align="left" class="titlebar">
                    <nobr>信息提交-信息编辑</nobr>
                </td>
                <td style="width:98%" align="right">
                    <nobr>
                        &nbsp;
                    </nobr>
                </td>
                <td align="right">
                    <div class="tbSeparatorEnd"></div>
                </td>
            </tr>
        </table>
        <table border="0" class="tableborder" cellspacing="0" cellpadding="0" align="center" width="98%">
            <tr>
                <td align="right" style="width:15%" class="pformleft">信息标题</td>
                <td style="width:35%" class="pformrightline">
                    <input type="text" id="txtNewsTitle" runat="server" class="input" style="width:99.4%" />
                </td>
                <td align="right" style="width:15%" class="pformleft">所属栏目</td>
                <td style="width:35%" class="pformright">
                    <asp:DropDownList ID="ddlColumn" runat="server" CssClass="inputselect" Width="99.4%"></asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td align="right" class="pformleft">信息设置</td>
                <td class="pformrightline">
                    <nobr>
                        <input type="checkbox" id="chkTop" runat="server" class="checkbox" /><label for="chkTop">信息置顶</label>&nbsp;
                        <input type="checkbox" id="chkAllowDiscuss" class="checkbox" runat="server" /><label for="chkAllowDiscuss">允许发表评论</label>&nbsp;
                        <input type="checkbox" id="chkHasImage" onclick="doShowSelImage()" class="checkbox" runat="server" /><label for="chkHasImage">有导航图片</label>
                        <a href="javascript:doSelectImage()" id="haSelImage" runat="server" class="linktext"><img  runat="server" src="../images/toolbar/setimage.GIF" /></a>
                    </nobr>
                </td>
                <td align="right" class="pformleft">内容格式</td>
                <td class="pformright">
                    <nobr>
                        <input type="radio" name="radContentType" class="radiobutton" checked="true" onclick="doLoad()" id="radHtml" value="0" runat="server" /><label for="radHtml">HTML</label>
                        <input type="radio" name="radContentType" class="radiobutton" id="radWord" onclick="doLoad()" value="1" runat="server" /><label for="radWord">WORD</label>
                        <input type="radio" name="radContentType" class="radiobutton" id="radExcel" onclick="doLoad()" value="2" runat="server" /><label for="radExcel">EXCEL</label>
                        <input type="radio" name="radContentType" class="radiobutton" id="radUrl" onclick="doLoad()" value="3" runat="server" /><label for="radUrl">链接信息</label>
                    </nobr>
                </td>
            </tr>
            <tr id="trUrl" runat="server" style="display:none">
                <td align="right" class="pformleft">链接地址</td>
                <td class="pformright" colspan="3">
                    <input type="text" id="txtUrl" runat="server" style="width:99.4%" value="http://www." class="input" />
                </td>                
            </tr>
            <tr id="trHtmlContent" runat="server">
                <td colspan="4" class="pformright">
                    <FTB:FreeTextBox ID="ftbContent" Width="100%" Height="400px" runat="server" FontFacesMenuPath="../CSS/">
                    </FTB:FreeTextBox>
                </td>
            </tr>
            <tr id="EDITOR_WORD" runat="server" style="display:none">
				<td class="pformright" colspan="4" style="width:100%">
					<table height="450" cellSpacing="0" cellPadding="0" width="100%" align="center">
						<tr>
							<td id="tdWebOfficeObject" bgColor="menu" height="100%" runat="server">
							    <object id="WebOffice" width="100%" height="100%" classid="clsid:8B23EA28-723C-402F-92C4-59BE0E063499" codebase="../ocx/iWebOffice2006.cab#version=7,8,0,4"></object>
							</td>
						</tr>
					</table>
				</td>
			</tr>
            <tr>
                <td colspan="4" align="left" class="pformleft">&nbsp;&nbsp;&nbsp;附件
                    <a href="javascript:doUploadFile()" runat="server" class="linktext">上传附件</a>
                </td>
            </tr>
            <tr>
                <td colspan="4" class="pformleft" align="left">
                    <ccit:attach id="ucAttach" ShowStyle="1" runat="server"></ccit:attach>
                </td>
            </tr>
            <tr>
                <td class="pformstrip" colspan="4" align="center">
                    <input type="button" id="btnSave" runat="server" class="button" onclick="doSave('1')" value="保存" />&nbsp;
                    <input type="button" id="btnSaveContiune" runat="server" class="button" onclick="doSave('2')" value="保存并新增" />&nbsp;
                    <input type="button" id="btnSaveBack" runat="server" class="button" onclick="doSave('3')" value="保存并返回" />&nbsp;
                    <input type="button" id="btnBack" runat="server" class="button" onclick="doBack()" value="返回" />
                </td>
            </tr>
        </table>
    </ccit:ActionForm>
</body>
</html>
